package cate.common.table.activity.spiceup.sheet;

import cate.common.table.ESheet;
import cate.common.table.activity.spiceup.row.SpiceUpWeightRow;
import cate.common.util.random.RWList;

import java.util.HashMap;
import java.util.Map;

public class SpiceUpWeightSheet extends ESheet<SpiceUpWeightRow> {
    @Override
    public String getSheetName() {
        return "up概率";
    }

    private Map<Integer, RWList<SpiceUpWeightRow>> groupMap;

    @Override
    protected void onLoaded() {
        groupMap = new HashMap<>();
        for (SpiceUpWeightRow row : this.list) {
            RWList<SpiceUpWeightRow> rwList = groupMap.get(row.groupId);
            if (rwList == null) {
                rwList = new RWList<>();
                groupMap.put(row.groupId, rwList);
            }
            rwList.add(row);
        }
        groupMap.values().forEach(RWList::setup);
    }

    public SpiceUpWeightRow randomReward(int groupId) {
        RWList<SpiceUpWeightRow> rwList = groupMap.get(groupId);
        if (rwList == null) {
            return null;
        }
        return rwList.get();
    }
}
